﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>WinSetTransparent - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The WinSetTransparent function makes the specified window semi-transparent." />
<meta name="ahk:equiv-v1" content="commands/WinSet.htm#Transparent" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>WinSetTransparent</h1>

<p>Makes the specified window semi-transparent.</p>

<pre class="Syntax"><span class="func">WinSetTransparent</span> <span class="optional">N, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>

<h2 id="Parameters">参数</h2>
<dl>
    <dt>N</dt>
    <dd>
        <p>类型: <a href="../Concepts.htm#numbers">整数</a>或<a href="../Concepts.htm#strings">字符串</a></p>
        <p>To enable transparency, specify a number between 0 and 255 indicating the degree of transparency: 0 makes the window invisible while 255 makes it opaque.</p>
        <p>The word <code>"Off"</code> (case-insensitive) may be specified to completely turn off transparency for a window. This is functionally identical to <code><a href="WinSetTransColor.htm">WinSetTransColor</a> "Off", <i>WinTitle</i></code>. Specifying <code>"Off"</code> is different than specifying 255 because it may improve performance and reduce usage of system resources (but probably only when desktop composition is disabled).</p>
    </dd>
    <dt>WinTitle</dt>
    <dd>
        <p>类型: <a href="../Concepts.htm#strings">字符串</a>, <a href="../Concepts.htm#numbers">整数</a>或<a href="../Objects.htm">对象</a></p>
        <p>识别目标窗口的窗口标题或其他条件. 请参阅 <a href="../misc/WinTitle.htm">WinTitle</a>.</p>
    </dd>
    <dt>WinText</dt>
    <dd>
        <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
        <p>如果存在, 此参数必须是目标窗口的单个文本元素的子字符串(和内置的 Window Spy 工具显示的一样). 如果 <a href="DetectHiddenText.htm">DetectHiddenText</a> 为 ON, 那么会检测隐藏文本元素.</p>
    </dd>
    <dt>ExcludeTitle</dt>
    <dd>
        <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
        <p>标题中含有此参数值的窗口将被排除.</p>
    </dd>
    <dt>ExcludeText</dt>
    <dd>
        <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
        <p>文本中含有此参数值的窗口将被排除.</p>
    </dd>
</dl>

<h2 id="Return_Value">返回值</h2>
<p>类型: <a href="../Concepts.htm#boolean">整数(布尔值)</a></p>
<p>函数返回 1(true) 表示成功, 或 0(false) 表示失败.</p>

<h2 id="Error_Handling">错误处理</h2>
<p>如果遇到问题, <a href="../misc/ErrorLevel.htm">ErrorLevel</a> 设置为 1, 否则设置为 0. 如果找不到目标窗口或无法应用更改, 则失败.</p>

<h2 id="Remarks">备注</h2>
<p>例如, to make the task bar transparent, use <code>WinSetTransparent 150, "ahk_class Shell_TrayWnd"</code>. Similarly, to make the classic Start Menu transparent, 请参阅 <a href="#ExTransStartMenu">示例 #1</a>. To make the Start Menu's submenus transparent, also include the script from <a href="#ExTransMenu">示例 #2</a>.</p>
<p>Setting the transparency level to 255 before using <code>"Off"</code> might avoid window redrawing problems such as a black background. If the window still fails to be redrawn correctly, 请参阅 <a href="WinRedraw.htm">WinRedraw</a> for a possible workaround.</p>
<p>鼠标光标下的窗口的 ID 可以使用 <a href="MouseGetPos.htm">MouseGetPos</a> 来获取.</p>
<p>窗口标题和文本是区分大小写的. 除非 <a href="DetectHiddenWindows.htm">DetectHiddenWindows</a> 被打开, 否则不会检测隐藏窗口.</p>

<h2 id="Related">相关</h2>
<p><a href="WinSetTransColor.htm">WinSetTransColor</a>, <a href="Win.htm">Win functions</a>, <a href="Control.htm">Control functions</a></p>

<h2 id="Examples">示例</h2>
<div class="ex" id="ExTransStartMenu">
<p><a href="#ExTransStartMenu">#1</a>: Makes the classic Start Menu transparent (to additionally make the Start Menu's submenus transparent, see <a href="#ExTransMenu">example #2</a>):</p>
<pre>DetectHiddenWindows True
WinSetTransparent 150, "ahk_class BaseBar"</pre>
</div>

<div class="ex" id="ExTransMenu">
<p><a href="#ExTransMenu">#2</a>: To make all or selected menus on the entire system transparent, keep a script such as the following always running. Note that although such a script cannot make its own menus transparent, it can make those of other scripts transparent:</p>
<pre>SetTimer "WatchForMenu", 5

WatchForMenu()
{
    DetectHiddenWindows True  <em>; Might allow detection of menu sooner.</em>
    if WinExist("ahk_class #32768")
        WinSetTransparent 150  <em>; Uses the window found by the above line.</em>
}</pre>
</div>

<div class="ex" id="ExTransHotkey">
<p><a href="#ExTransHotkey">#3</a>: Here are some hotkeys that demonstrate the effects of WinSetTransparent and <a href="WinSetTransColor.htm">WinSetTransColor</a>. NOTE: If you press one of the hotkeys while the mouse cursor is hovering over a pixel that is invisible as a result of TransColor, the window visible beneath that pixel will be acted upon instead!</p>
<pre>#t::  <em>; Press Win+T to make the color under the mouse cursor invisible.</em>
MouseGetPos MouseX, MouseY, MouseWin
MouseRGB := PixelGetColor(MouseX, MouseY)
<em>; It seems necessary to turn off any existing transparency first:</em>
WinSetTransColor "Off", "ahk_id " MouseWin
WinSetTransColor MouseRGB " 220", "ahk_id " MouseWin
return

#o::  <em>; Press Win+O to turn off transparency for the window under the mouse.</em>
MouseGetPos ,, MouseWin
WinSetTransColor "Off", "ahk_id " MouseWin
return

#g::  <em>; Press Win+G to show the current settings of the window under the mouse.</em>
MouseGetPos ,, MouseWin
Transparent := WinGetTransparent("ahk_id " MouseWin)
TransColor := WinGetTransColor("ahk_id " MouseWin)
ToolTip "Translucency:`t" Transparent "`nTransColor:`t" TransColor
return</pre>
</div>

</body>
</html>